package org.gavin.sharding.algorithms;

import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;

import java.util.Collection;
import java.util.Properties;

/**
 * UserDataTableAlgorithm
 *
 * @author grl
 * @date 2024/2/1
 */
public class UserDataTableAlgorithm implements StandardShardingAlgorithm<Long> {

    @Override
    public String doSharding(Collection<String> databaseNames, PreciseShardingValue<Long> shardingValue) {
        for (String databaseName : databaseNames) {
            if (databaseName.endsWith(String.valueOf(shardingValue.getValue() % 2 + 1))) {
                return databaseName;
            }
        }
        throw new IllegalArgumentException();
    }

    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
        return null;
    }

    @Override
    public String getType() {
      //  return StandardShardingAlgorithm.super.getType();
        return "UserDataTableAlgorithm";
    }

    @Override
    public Properties getProps() {
        return null;
    }

    @Override
    public void init(Properties properties) {
        System.currentTimeMillis();
    }
}
